package com.project.server.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.server.common.Result;
import com.project.server.model.Dish;
import com.project.server.service.DishService;
import com.project.server.vo.DishVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "菜品管理")
@RestController
@RequestMapping("/api/dish")
@RequiredArgsConstructor
public class DishController {

    private final DishService dishService;

    @Operation(summary = "分页查询菜品列表")
    @GetMapping("/page")
    public Result<Page<DishVO>> page(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Long categoryId,
            @RequestParam(required = false) Long restaurantId,
            @RequestParam(required = false) Integer status) {
        return Result.success(dishService.page(pageNum, pageSize, name, categoryId, restaurantId, status));
    }

    @Operation(summary = "获取菜品详情")
    @GetMapping("/{id}")
    public Result<Dish> getById(@PathVariable Long id) {
        return Result.success(dishService.getById(id));
    }

    @Operation(summary = "新增菜品")
    @PostMapping
    public Result<Void> save(@RequestBody @Validated Dish dish) {
        dishService.save(dish);
        return Result.success();
    }

    @Operation(summary = "更新菜品")
    @PutMapping
    public Result<Void> update(@RequestBody @Validated Dish dish) {
        dishService.update(dish);
        return Result.success();
    }

    @Operation(summary = "删除菜品")
    @DeleteMapping("/{id}")
    public Result<Void> remove(@PathVariable Long id) {
        dishService.removeById(id);
        return Result.success();
    }

    @Operation(summary = "更新菜品状态")
    @PutMapping("/status/{id}/{status}")
    public Result<Void> updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        dishService.updateStatus(id, status);
        return Result.success();
    }

    @Operation(summary = "获取餐厅热销菜品")
    @GetMapping("/hot/{restaurantId}")
    public Result<List<Dish>> getHotDishes(
            @PathVariable Long restaurantId,
            @RequestParam(defaultValue = "10") Long pageSize) {
        return Result.success(dishService.getHotDishes(restaurantId, pageSize));
    }






}
